package com.carb.controller.member;

import com.carb.dto.BusinessAddDTO;
import com.carb.enums.BusinessStatus;
import com.carb.result.Result;
import com.carb.service.IBusinessService;
import com.carb.vo.BusinessVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 业务管理 前端控制器
 * </p>
 *
 * @author XuChaoyang
 * @since 2025-01-18
 */
@RestController("memberBusinessController")
@RequestMapping("/member/business")
@Tag(name = "业务管理相关接口")
@Slf4j
public class BusinessController {

    @Resource
    private IBusinessService businessService;

    /**
     * 会员新增业务
     * @param businessAddDTO 新增业务数据模型
     */
    @PostMapping("/add")
    @Operation(summary = "会员新增业务")
    public Result<String> addBusinessForMember(@RequestBody BusinessAddDTO businessAddDTO) {
        log.info("会员新增业务：{}", businessAddDTO);
        businessService.addBusinessForMember(businessAddDTO);
        log.info("会员新增业务成功！");
        return Result.success();
    }

    /**
     * 会员自身业务数量查询
     * @param businessStatus 业务状态
     * @return 业务数量
     */
    @GetMapping("/count/{businessStatus}")
    @Operation(summary = "会员自身业务数量查询")
    public Result<Long> countBusinessForMember(@PathVariable @Parameter(description = "业务状态") BusinessStatus businessStatus) {
        log.info("会员自身业务数量查询：{}", businessStatus);
        Long count = businessService.countBusinessForMember(businessStatus);
        log.info("会员自身业务数量查询成功！");
        return Result.success(count);
    }

    /**
     * 会员自身业务查询
     * @param businessStatus 业务状态
     * @return 业务列表
     */
    @GetMapping("/list/{businessStatus}")
    @Operation(summary = "会员自身业务查询")
    public Result<List<BusinessVO>> listBusinessForMember(@PathVariable @Parameter(description = "业务状态") BusinessStatus businessStatus) {
        log.info("会员自身业务查询：{}", businessStatus);
        List<BusinessVO> businessVOList = businessService.listBusinessForMember(businessStatus);
        log.info("会员自身业务查询成功！");
        return Result.success(businessVOList);
    }

    /**
     * 业务退款
     * @param id 业务id
     */
    @PutMapping("/refund/{id}")
    @Operation(summary = "业务退款")
    public Result<String> refundBusiness(@PathVariable @Parameter(description = "业务id") Long id) {
        log.info("业务退款：{}", id);
        businessService.refundBusiness(id);
        log.info("业务退款成功！");
        return Result.success();
    }

}
